<%--
  Created by IntelliJ IDEA.
  User: yanwen
  Date: 16-11-1
  Time: 下午3:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
<div class="modal-dialog modal-lg">
    <div class="modal-content">

        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
            </button>
            <h4 class="modal-title" id="myModalLabel">新增表单</h4>
        </div>
        <div class="modal-body">
            <form id="addForm" data-parsley-validate="" class="form-horizontal form-label-left">
                <div class="form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12"><span class="required required-the-symbol">*</span> 表单名称:
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12">
                        <input name="name" type="text"
                               class="form-control col-md-7 col-xs-12" maxlength="20" placeholder='空白表单'>
                        <input name="memberId" type="hidden" value="${memberId}">
                    </div>
                </div>
                <div class="ln_solid" style="border-bottom:1px solid #e5e5e5"></div>
                <div class="form-group">
                    <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3" style="margin-top: 20px">
                        <input id="doAddButton" class="btn btn-primary" value="提 交" type="button">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<script>

    //提交添加渠道表单
    $(document).ready(function () {
        $("#doAddButton").click(function(){
            $("#addForm").submit();
        });
        $('#addForm').bootstrapValidator({
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '请输入表单名称'
                        },
                        stringLength: {
                            max: 20,
                            message: '最多输入20个字'
                        }, callback: {
                            message: "表单名称不可重复",
                            callback: function (value, validator) {
                                var message = "success";
                                $.ajax({
                                    url: '/ajax/front/forms/check_name',
                                    type: 'get',
                                    data: {name: value},
                                    dataType: 'json',
                                    async: false,
                                    success: function (data, status, xhr) {
                                        message = data
                                    }
                                })
                                if (message == "success") {
                                    return true
                                }
                                return false;
                            }
                        }
                    }
                }
            }

        }).on('success.form.bv', function (e) {
            $.ajax({
                url: '/front/forms/add',
                type: 'post',
                data: $('#addForm').serialize(),
                dataType: 'json',
                async: false,
                success: function (data, status, xhr) {
                        $('#addModal').modal("hide");
                        showMsg("success", "添加成功")
                        window.location.href = "/front/forms/"+data+"/edit";
                }
            });
            return false;//防止form表单提交
        });
    })
</script>